<h1> Orders Manage </h1>
<?php require_once 'CMS/Util.php';
$tb_Things=new Admin_Model_Things();
$dateInt = new Util();?>

<div class="breadcrumb">
        <a href="/admin/index">Home</a>
         :: <a href="/admin/bill">Orders</a>
</div>
<?php  if(isset($this->result)) 
{ if($this->result==1)
	{?>
		<div class="success" style="text-align: center;">Cancel Order Successfully</div>
	<?php
	}
	else 
	{
		if($this->result==2)
		{
		?>
		<div class="warning" style="text-align: center;">Cancel Order Failed! Order Finished</div>
		<?php 
		}
		else 
		{
			?>
			<div class="warning" style="text-align: center;">Cancel Order Failed!</div>
			<?php 
		}
	} 
}?>
<div class="box">
 <div class="heading">
      <h1><img alt="" src="/images/admin/order.png"> Orders</h1>
      <div class="buttons">
      	<a onclick="window.open('/admin/billdetail/print?id=<?php echo $_GET["id"]?>');" class="button"><span>Print</span></a>
      	<a onclick="location = '/admin/billdetail?id=<?php echo $_GET["id"]?>&&act=1';" class="button"><span>Cancel</span></a></div>
    </div>
    <div class="content">
    	<div class="vtabs"><a class="" tab="#tab_order">Order</a><a class="" tab="#tab_product">Products</a><a class="selected" tab="#tab_history">History Order</a></div>
    	<div style="display: none;" id="tab_order" class="vtabs_page">
        <table class="form" >
          <tbody>
          <?php if(count($this->Bill)!=0)
          foreach ($this->Bill as $bill){?>
          <tr>
            <td>Order ID:</td>
            <td><?php echo $bill["bill_id"]?></td>
          </tr>

                    <tr>
            <td>Customer name:</td>
            <td><?php echo $bill["full_name"]?></td>
          </tr>
          
          <tr>
            <td>E-Mail:</td>
            <td><?php echo $bill["email"]?></td>
          </tr>
          <tr>
            <td>Phone:</td>
            <td><?php echo $bill["phone"]?></td>
          </tr>
                    <tr>
            <td>Yahoo:</td>
            <td><?php echo $bill["yahoo"]?></td>
          </tr>
                  
          <tr>
            <td>Created date:</td>
            <?php $Update_Date=$dateInt->makeDays($bill["updated_date"]); ?>
            <td><?php echo $Update_Date?></td>
          </tr>
          <tr>
            <td>Delivery Address:</td>
            <td><?php echo $bill["d_address"]?></td>
          </tr>
          <?php $ship_time=unserialize($bill["ship_time"])?> 
          <tr>
            <td>Ship time:</td>
            <td><?php echo $ship_time['gio'].":".$ship_time['phut']." ",$ship_time['ngay']."/".$ship_time['thang']."/".$ship_time['nam']?></td>
          </tr>                   
          <tr>
            <td>Total Price:</td>
            <td class="grand_total"><?php echo number_format($bill["total_bill_price"])?> VNĐ</td>
          </tr>
                    
          <tr>
            <td>Status:</td>
            <td id="order_status"><?php echo $bill["status_name"]?></td>
          </tr>

        </tbody><?php }?>
        </table>
      </div>
      
      <div style="display: none;" id="tab_product" class="vtabs_page">
        <table id="product" class="list" >
        <?php if(count($this->BillDetail)){$i=0;?>
          <thead>
            <tr style="background-color: rgb(244, 244, 248);">
              <td>No</td>
              <td class="left">Product</td>
              <td class="left">Product ID</td>
              <td class="right">Quantity</td>
              <td class="right">Price</td>
              <td class="right">Total Price</td>
            </tr>
          </thead>
	          <?php foreach ($this->BillDetail as $billdetail)
	          {$i++;
	          $thingdetail=$tb_Things->getThingById($billdetail['thing_id']);
	          ?>
	            <tbody id="product_203">
	            <tr>
	              <td class="left" style="width: 3px;"><?php echo $i;?></td>
	              <td class="left"><a href="/index/detail?id=<?php echo $billdetail['thing_id']?>"><?php echo $thingdetail[0]['title']?></a>
	                </td>
	              <td class="left"><?php echo $billdetail['thing_id']?></td>
	              <td class="right"><?php echo $billdetail['quantity']?></td>
	              <td class="right"><?php echo number_format($billdetail['price'])?> VNĐ</td>
	              <td class="right"><?php echo number_format($billdetail['total_price'])?> VNĐ</td>
	            </tr>
	          </tbody> 
	          <?php }
	          }?>    	    
        </table>
      </div>
      
      <div style="display: block;" id="tab_history" class="vtabs_page">
                <table class="list" >
                 <?php if(count($this->Bill)!=0)
          foreach ($this->Bill as $bill){?>
          <thead>
            <tr style="background-color: rgb(244, 244, 248);">
              <td class="left" width="33.3%"><b>Date</b></td>
              <td class="left" width="33.3%"><b>Status</b></td>
              <!-- <td class="left" width="33.3%"><b>Thông báo khách hàng</b></td> -->
            </tr>
          </thead>
          <tbody>
            <tr>
            <?php $Update_Date=$dateInt->makeDays($bill["updated_date"]); ?>
              <td class="left"><?php echo $Update_Date?></td>
              <td class="left"><?php echo $bill['status_name']?></td>
              <!-- <td class="left">Có</td> -->
            </tr>
          </tbody>

        </table>
                <input style="display: none;" name="append" value="1" checked="checked" type="checkbox"><textarea style="display: none;" name="comment" cols="40" rows="8"></textarea>
                <table class="form">
          <tbody><tr>
            <td>Order Status:</td>
            <td><select name="order_status_id" id="order_status_id">
            <?php foreach ($this->BillStatus as $status){?>
                     <option value="<?php echo $status['status_id']?>" <?php if($status['status_name']==$bill['status_name']){?> selected="selected"<?php }?>><?php echo $status['status_name']?></option><?php }?>
                </select></td>
          </tr>
			<input name="notify" value="1" type="hidden">

            
          
          <tr>
            <td></td>
            <td>
              <div style="margin-top: 10px; text-align: right;"><a onclick="UpdateStatus('<?php echo $_GET["id"]?>');" id="history_button" class="button"><span>Save</span></a></div></td>
          </tr>
        </tbody><?php }?></table>
      </div>
      
    </div>
  </div>
<script type="text/javascript"><!--
$.tabs('.vtabs a');
//--></script>
<script type="text/javascript">
function UpdateStatus(bill_id)
{ 
	var status_id=document.getElementById("order_status_id").value;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function()
	{	
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("tab_history").innerHTML=xmlhttp.responseText;
		}	
	};
	var url = "/admin/billdetail/update?id="+bill_id+"&&status="+status_id;
	//alert(_title);
	xmlhttp.open("GET",url,true);	
	xmlhttp.send();
	return false;
}
</script>